using System;

namespace NodeBasedSkillEditor.Model.Node.RT
{
    public class Node_Reciprocal_RT : RT_Node
    {
        public RT_SingleValuePort Origin_RT;

        public RT_SingleValuePort Reciprocal_RT;

        public Node_Reciprocal_RT(Node_Reciprocal sourceData, RT_DAG parentDag) : base(sourceData, parentDag)
        {
            Origin_RT = new RT_SingleValuePort(EPortIOType.Input, sourceData.Origin, this);

            Reciprocal_RT = new RT_SingleValuePort(EPortIOType.Output, sourceData.Reciprocal, this);
            Reciprocal_RT.OnGetValue = GetReciprocal;
        }

        public AValue GetReciprocal(DAG_Executor executor)
        {
            Reciprocal_RT.SourceValue.Reset();
            var scalar = (Origin_RT.GetValue(executor) as Value_Scalar).Value;
            if (scalar != 0)
            {
                Reciprocal_RT.SourceValue.SetScalar(1 / scalar);
            }
            else
            {
#if UNITY_EDITOR
                throw new DivideByZeroException(); 
#endif
            }

            return Reciprocal_RT.SourceValue;
        }


    }
}